const util = {
	//提示框
	logStr:(str) => {
	    uni.showToast({
	    	title: str,
	    	icon: 'none',
	    	duration: 2600
	    });
	},
	
	//页面跳转
	jumpUrl:(url)=>{
	    uni.navigateTo({
			url: url
		});
	},
	
	//打电话
	makePhone(tel){
	    uni.makePhoneCall({
	    	phoneNumber: tel,
	    	fail(e){}
	    });
	},
	
	stringToNum(val){
	    const newVal = val ? Number(val) : null;
		return newVal
	},
	
	//获取当前时区
	getTimeZone(){
	    var offset = new Date().getTimezoneOffset();
	    var sign = offset < 0? "" : "-";
	    var hours = Math.abs(Math.floor(offset / 60));
	    return Number(sign + hours); //+ ":" + ("0" + minutes).slice(-2);
	},
	
	//设置时间日期格式
	setDateFormat(dateVal){
		if(dateVal){
			const date = dateVal.slice(0,10);
			const time = dateVal.slice(10);
			const year = new Date(dateVal).getFullYear();
			const mon = new Date(dateVal).getMonth() + 1;
			const month = mon > 9 ? mon : "0" + mon;
			const daily = new Date(dateVal).getDate();
			const day = daily > 9 ? daily : "0" + daily;
			const dateFormat = uni.getStorageSync('dateFormat') || 'DMY';
			const monToEn = {
				'01':"January",
				'02':"February",
				'03':"March",
				'04':"April",
				'05':"May",
				'06':"June",
				'07':"July",
				'08':"August",
				'09':"September",
				'10':"October",
				'11':"November",
				'12':"December"
			}
			if(dateFormat == "MDY"){
				return month + '/'+ day + '/' + year + time
			}
			else if(dateFormat == "DMY"){
				return day + '/'+ month + '/' + year + time
			}
			else if(dateFormat == "Y-M-D"){
				return year + '-'+ month + '-' + day + time
			}
			else if(dateFormat == "Y/M/D"){
				return year + '/'+ month + '/' + day + time
			}
			else if(dateFormat == "MonDY"){
				return monToEn[String(month)] + " "+day + ',' + year + time
			}
			else if(dateFormat == "DMonY"){
				return day + " " + monToEn[String(month)] + " "+ year + time
			}
		}
		else{
			return ""
		}
	}
}

export default util
